<template>
  <div class="title-bar">
    <div
      class="arrow-left"
      @click="onLeftArrow"
    >
      <span></span>
    </div>
    <h1>{{title}}</h1>
    <div class="title-bar-right">
      <slot name="right"></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: ''
    },
    backFunction: {
      type: Function,
      default: null
    }
  },
  methods: {
    onLeftArrow() {
      if (this.backFunction) {
        this.backFunction()
      } else {
        this.$router.back()
      }
    }
  }
}
</script>

<style scoped lang="scss">
.title-bar {
  position: relative;
  width: 100%;
  height: 0.88rem;
  line-height: 0.88rem;
  background-color: #fff;
  h1 {
    width: 100%;
    text-align: center;
    font-size: 0.36rem;
    color: rgba(51, 51, 51, 1);
    font-weight: 700;
  }
  .arrow-left {
    position: absolute;
    left: 0;
    top: 0;
    padding: 0 0.3rem;
    height: 100%;
    span {
      display: inline-block;
      width: 0.3rem;
      height: 0.3rem;
      border-top: 1px solid #333;
      border-left: 1px solid #333;
      transform: rotate(-45deg);
    }
  }
}
</style>
